//
//  LabelUtil.m
//  YiJuZhangShou
//
//  Created by URANUS on 16/3/12.
//  Copyright © 2016年 Uranus. All rights reserved.
//

#import "LabelUtil.h"
#import "Masonry.h"
#import "UILabel+XExtension.h"
@implementation LabelUtil

#pragma mark Public
+(UILabel *)loadLabelWithBarViewWithBackView:(UIView *)backView
                               withTitleEdge:(UIEdgeInsets)edge
                                 andBarColor:(UIColor *)barColor{
    UILabel *titleLabel = [[UILabel alloc] init];
    UIView *barView = [[UIView alloc] init];
    barView.tag = 1;
    barView.backgroundColor = barColor;
    [backView addSubview:titleLabel];
    [backView addSubview:barView];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView).offset(edge.left);
        make.top.equalTo(backView).offset(edge.top);
        make.bottom.equalTo(backView).offset(edge.bottom);
    }];
    [barView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLabel.mas_bottom);
        make.left.right.equalTo(backView);
        make.height.equalTo(1);
    }];
    
    return titleLabel;
}

+(UILabel *)loadLabelWithTitleLabelWithBackView:(UIView *)backView
                                      withTitle:(NSString *)title
                                  withTitleColor:(UIColor *)titleColor
                                   andTitleFont:(UIFont *)titleFont{
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = title;
    titleLabel.textColor = titleColor;
    titleLabel.font = titleFont;
    titleLabel.tag = TitleLabelTag;
    UILabel *contentLabel = [[UILabel alloc] init];
    contentLabel.textColor = titleColor;
    contentLabel.font = titleFont;
    
    [backView addSubview:titleLabel];
    [backView addSubview:contentLabel];
    
    CGRect titleRect = [titleLabel setXFont:titleLabel.font];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView);
        make.left.equalTo(backView);
        make.width.mas_equalTo(titleRect.size.width+5);
        make.bottom.lessThanOrEqualTo(backView);
    }];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(5);
        make.top.equalTo(titleLabel);
        make.right.equalTo(backView);
        make.bottom.lessThanOrEqualTo(backView);
    }];
    
    return contentLabel;
}


+ (void)loadLabelWithTitle:(NSString *)title
                  withUnit:(NSString *)unit
                 withLabel:(UILabel *)label
               andBackView:(UIView *)backView{
    UILabel *titleLabel = [UILabel new];
    titleLabel.font = TextFont14;
    titleLabel.text = title;
    titleLabel.tag = TitleLabelTag;
    titleLabel.textColor = TextColor120;
    UILabel *unitLabel = [UILabel new];
    unitLabel.text = unit;
    unitLabel.tag = UnitLabelTag;
    unitLabel.font = TextFont14;
    unitLabel.textColor = TextColor120;
    label.textAlignment = NSTextAlignmentCenter;
    
    [backView addSubview:titleLabel];
    [backView addSubview:label];
    [backView addSubview:unitLabel];
    
    CGRect titleRect = [titleLabel setXFont:titleLabel.font];
    CGRect unitRect = [unitLabel setXFont:unitLabel.font];
    
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backView);
        make.top.bottom.equalTo(backView);
        make.width.mas_equalTo(titleRect.size.width);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(5);
        make.top.bottom.equalTo(backView);
    }];
    [unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label.mas_right).offset(5);
        make.top.bottom.equalTo(backView);
        make.right.equalTo(backView);
        make.width.mas_equalTo(unitRect.size.width+3);
    }];
}


@end
